<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" href="../../jquery-easyui-1.3.6/themes/default/easyui.css" type="text/css"></link>
	<link rel="stylesheet" href="../../css/icons/icon.css" type="text/css"></link>
	<link rel="stylesheet" type="text/css" href="../demo.css"></link>
	<script type="text/javascript" src="../../jquery-easyui-1.3.6/jquery.min.js"></script>
	<script type="text/javascript" src="../../jquery-easyui-1.3.6/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../jquery-easyui-1.3.6/locale/easyui-lang-zh_CN.js"
	charset="utf-8"></script>
	<script type="text/javascript" src="../../Exteasyui/datetimebox.js"></script>
	<script type="text/javascript" src="../../Exteasyui/footer.js"></script>
	<script type="text/javascript">
	function mergeCellsByField(tableID,colList){
            var ColArray = colList.split(",");
            var tTable = $('#'+tableID);
            var TableRowCnts=tTable.datagrid("getRows").length;
            var tmpA;
            var tmpB;
            var PerTxt = "";
            var CurTxt = "";
            var alertStr = "";
            //for (j=0;j<=ColArray.length-1 ;j++ )
            for (j=ColArray.length-1;j>=0 ;j-- )
            {
                //当循环至某新的列时，变量复位。
                PerTxt="";
                tmpA=1;
                tmpB=0;
                
                //从第一行（表头为第0行）开始循环，循环至行尾(溢出一位)
                for (i=0;i<=TableRowCnts ;i++ )
                {
                    if (i==TableRowCnts)
                    {
                        CurTxt="";
                    }
                    else
                    {
                        CurTxt=tTable.datagrid("getRows")[i][ColArray[j]];
                    }
                    if (PerTxt==CurTxt)
                    {
                        tmpA+=1;
                    }
                    else
                    {
                        tmpB+=tmpA;
                        tTable.datagrid('mergeCells',{
                            index:i-tmpA,
                            field:ColArray[j],
                            rowspan:tmpA,
                            colspan:null
                        });
                        tmpA=1;
                    }
                    PerTxt=CurTxt;
                }
            }
        }
		$(function(){
            $('#tt').datagrid({
			    view:myview,//datagrid添加footer设置新样式
                title:'',
                iconCls:'',
                width:600,
                height:420,
                nowrap: false,
                striped: true,
				fitColumns: true,
				singleSelect: true,
				rownumbers: true,
				border:false,
				showFooter:true,
				pagination:true,
				fit:true,
                url:'cost.json',
                sortName: 'doc_no',
                //sortOrder: 'desc',
                remoteSort: false,
                idField:'doc_no',
				rowStyler:function(index,row){   
                    if (row.drive_time=='收支总计:'){   
                    return 'background-color:#6293BB;color:#fff;font-weight:bold;';   
                    }   
                },
                onLoadSuccess:function(data){
                    if (data.rows.length>0)
                    {
                        setTimeout("mergeCellsByField(\"tt\",\"doc_no,client,type,no,driver,drive_time,income,expenses\")",2000); 
                        //mergeCellsByField("test","name,code,addr");
                    }
                },
				//onLoadSuccess: compute,//加载完毕后执行求和运算
                frozenColumns:[[
                    {title:'托单号',field:'doc_no',width:100,sortable:true,halign:'center'},
					{title:'客户',field:'client',width:100,sortable:true,halign:'center'},
					{title:'业务类型',field:'type',width:100,sortable:true,halign:'center'},
					{title:'车牌号',field:'no',width:100,sortable:true,halign:'center'},
					{title:'司机',field:'driver',width:80,sortable:true,halign:'center'},
					{title:'出车日期',field:'drive_time',width:120,sortable:true,halign:'center',align:'right'}	
                ]],
                columns:[[
                    {title:'收入',colspan:4},
					{title:'支出',colspan:4},
                    
                ],[
                    {field:'tk_fee',title:'拖卡费',width:100,align:'right',halign:'center'},
                    {field:'dh_fee',title:'代货费',width:100,align:'right',halign:'center'},
                    {field:'income_others',title:'其他',width:100,align:'right',halign:'center'},
					{field:'income_total',title:'收入合计',width:100,align:'right',halign:'center'},
					{field:'aj_fee',title:'安检费',width:100,align:'right',halign:'center'},
                    {field:'repair',title:'维修费',width:100,align:'right',halign:'center'},
                    {field:'expenses_others',title:'其他',width:100,align:'right',halign:'center'},
					{field:'expenses_total',title:'支出合计',width:100,align:'right',halign:'center'}
                ]],
                toolbar:[{
                    id:'btnadd',
                    text:'增加',
                    iconCls:'icon-add',
                    handler:function(){
                        $('#btnadd').linkbutton('enable');
                        alert('add')
                    }
                },'-',{
                    id:'btnedit',
                    text:'修改',
                    iconCls:'icon-edit',
                    handler:function(){
                        $('#btnedit').linkbutton('enable');
                        alert('edit')
                    }
                },'-',{
                    id:'btncut',
                    text:'删除',
                    iconCls:'icon-cut',
                    handler:function(){
                        $('#btncut').linkbutton('enable');
                        alert('cut')
                    }
                },'-',{
                    id:'btnsave',
                    text:'保存',
                    disabled:false,
                    iconCls:'icon-save',
                    handler:function(){
                        $('#btnsave').linkbutton('enable');
                        alert('save')
                    }
                },'-',{
                    id:'btnexport',
                    text:'导出',
                    disabled:true,
                    iconCls:'icon-export',
                    handler:function(){
                        $('#btnexport').linkbutton('enable');
                        alert('export')
                    }
                }]
            });
        });
		 
            
        /*function compute() {//计算函数
            var rows = $('#tt').datagrid('getRows')//获取当前的数据行
            var itotal = 0//计算listprice的总和
            etotal=0;//统计unitcost的总和
            for (var i = 0; i < rows.length; i++) {
                itotal += rows[i]['income_total'];
                etotal += rows[i]['expenses_total'];
            }
            //新增一行显示统计信息
            $('#tt').datagrid('appendRow', { drive_time: '<b>统计：</b>', income_total: itotal, expenses_total: etotal });}*/
       
	</script>

       
</head>
<body>

	<table id="tt"></table>
	
</body>
</html>